<template>
	<div>
		<el-row :gutter="24">
			<el-col :span="1" style="margin-right:10px;">
				<p class="queryLabel">调拨状态:</p>
			</el-col>
			
			<el-col :span="4">
				<el-select size="small" v-model="condition.allocationStatus" placeholder="请选择调拨状态" clearable>
					<el-option v-for="item in list_status" :label="item.label" :value="item.value"></el-option>
				</el-select>
			</el-col>
			<el-col :span="1" style="margin-right:10px;">
				<p class="queryLabel">申请日期:</p>
			</el-col>
			<el-col :span="4">
				<el-date-picker v-model="data.firstStart" size="small" style="width:100%;" type="date" clearable placeholder="开始日期">
				</el-date-picker>
			</el-col>
			<el-col :span="1" style="margin-right:10px;">
				<p class="queryLabel">至:</p>
			</el-col>
			<el-col :span="4">
				<el-date-picker v-model="data.firstStarts" size="small" style="width:100%;" type="date" clearable placeholder="结束日期">
				</el-date-picker>
			</el-col>
		</el-row>
		<el-row :gutter="24">
			<el-col :span="1" style="margin-right:10px;">
				<p class="queryLabel">发出仓库:</p>
			</el-col>
			<el-col :span="4">
				<el-select size="small" v-model="condition.fromWarehouse" placeholder="请选择发出仓库" clearable>
					<el-option v-for="item in warehouseCombo" :label="item.label" :value="item.value"></el-option>
				</el-select>
			</el-col>
			<el-col :span="1" style="margin-right:10px;">
				<p class="queryLabel">接受仓库:</p>
			</el-col>
			<el-col :span="4">
				<el-select size="small" v-model="condition.aimWarehouse" placeholder="请选择接受仓库" clearable>
					<el-option v-for="item in warehouseCombo" :label="item.label" :value="item.value"></el-option>
				</el-select>
			</el-col>
			<el-col :span="5" style="padding-left: 0px;text-align: right">
				<el-button type="primary" size="small" v-on:click='scmQuery'>查 询</el-button>
			</el-col>
		</el-row>
		<el-row>
			<el-col :span="24">
				<el-table :data="tableData.dataList" border style="width: 100%;align-content: center;" @selection-change="handleSelectionChanges">
					<el-table-column type="selection" width="55" label="选择">
					</el-table-column>
					
					<!--<el-table-column prop="allocationReason" label="暂估价格">
					</el-table-column>-->
							
					<el-table-column label="发出仓库" prop="fromWarehouse" :formatter="fromWarehouseCov">
					</el-table-column>
					<el-table-column label="目标仓库" align="right" prop="aimWarehouse" :formatter="aimWarehouseCov">
					</el-table-column>
					<el-table-column label="调拨类型" align="right" prop="allocationType" :formatter="saleStatusCov">
					</el-table-column>
					<el-table-column label="调拨数量" align="right" prop="allocationNum">
					</el-table-column>
					<el-table-column label="申请人" align="right" prop="uName">
					</el-table-column>
					<el-table-column label="调拨状态" align="right" prop="allocationStatus" :formatter="statusCov">
					</el-table-column>
					<el-table-column label="操作" align="right">
						<template scope="scope">
							<el-button type="primary"  size="mini" @click.native.prevent="info(scope.$index)">明细</el-button>
						</template>
					</el-table-column>
				</el-table>
				<el-pagination small @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="CurentPage" :page-sizes="page.pageSizes" :page-size="page.pageSize" layout=" total,prev, pager, next" :total="tableData.total">
				</el-pagination>
			</el-col>
		</el-row>
		<!--<span>selected:   {{select_value.i1}}</span>-->
		<el-dialog title="调拨明细" v-model="dialogInfoShow" size="large">
			
			<el-col :span="24">
				<el-table :data="comFormData.allocationOrderDetailList" border style="width: 100%;align-content: center;" @selection-change="infoChenck">
					<el-table-column type="selection" width="60">
					</el-table-column>
					<el-table-column prop="vin" label="VIN" width="180">
					</el-table-column>
					<el-table-column prop="carSeries" label="车系名称" width="100">
					</el-table-column>
					<el-table-column prop="carModel" label="车型名称" width="150">
					</el-table-column>
					<el-table-column prop="configure" label="配置名称" width="150">
					</el-table-column>
					<el-table-column prop="carModelYear" label="车型年" width="100">
					</el-table-column>
					<el-table-column prop="appearanceCode" label="外观代码" width="100">
					</el-table-column>
					<el-table-column prop="appearanceName" label="外观颜色" width="100">
					</el-table-column>
					<el-table-column prop="trimCode" label="内饰代码" width="100">
					</el-table-column>
					<el-table-column prop="trimName" label="内饰名称" width="100">
					</el-table-column>
					<el-table-column prop="chooseCode" label="加装代码" width="100">
					</el-table-column>
					<el-table-column prop="chooseName" label="加装名称" width="100">
					</el-table-column>
				
				</el-table>
				
			</el-col>

		</el-dialog>
		
	</div>
</template>

<script>
	import moment from 'moment'
	export default{
		data:function() {
			/*var fff;*/
			return{
				//明细窗口显示
				dialogInfoShow:false,
				//仓库下拉
				warehouseCombo: [],
				// 车辆信息
				comFormData: {
					allocationOrder: {
						detailId: "",
						id: "",
						fromWarehouse: "", //  发出仓库
						aimWarehouse: "", //  接受仓库
						allocationType: "", //  调拨类型
						allocationDate: "", //  调拨时间
						allocationReason: "", //调拨原因
						arriveWarehouseDate: "", //预计回库时间
						allocationNum: "", //调拨数量
						uName: "", //调拨申请人
					},
					allocationOrderDetailList: [],
				},
				/*调拨状态option*/
				list_status:[
				{
					label:"已创建",
					value:"0"
				},
				{
					label:"已提交",
					value:"1"
				},
				{
					label:"已审核",
					value:"2"
				},
				],
				/*发出仓库option*/
				list_send:[
				{
					label:"S仓库1",
					value:"0"
				},
				{
					label:"S仓库2",
					value:"1"
				},
				{
					label:"S仓库3",
					value:"2"
				}],
				/*接收仓库option*/
				list_receive:[
				{
					label:"R仓库1",
					value:"0"
				},
				{
					label:"R仓库2",
					value:"1"
				},
				{
					label:"R仓库3",
					value:"2"
				}],
				/*option值*/
				select_value:{
					i1:"",
					i2:"",
					i3:"",
					i4:""
				},
				data: {
					firstStart: "",
					firstStarts: ""
				},
				//公司数据
				tableData: {
					total: 0,
					dataList: []
				},
				tableDatas: {
					total: 0,
					dataList: []
				},
				condition: {
					allocationStatus: "",
					applicationStartDate: "",
					applicationStopDate: "",
					fromWarehouse: "",
					aimWarehouse: "",
				},
				conditions: {
					invoiceStratDate: "",
					invoiceStopDate: "",
					inputName: ""
				},
				CurentPage:1,
				page:this.page
				
			}
		},
		methods:{
			//状态转换
			statusCov: function(row, column) {
				var temp = '';
				switch(row.allocationStatus) {
					case '0':
						temp = "已创建";
						break;
					case '1':
						temp = '已提交';
						break;
					case "2":
						temp = '已审核';
						break;
					default:
						''
						break
				};
				return temp;
			},
			/*查询*/
			scmQuery:function(){
				
				//this.$message.error("查询");
				/*alert("调拨状态："+this.condition.allocationStatus
				+"\n开始日期:"+this.condition.applicationStartDate
				+"\n结束日期:"+this.condition.applicationStopDate
				+"\n出库："+this.condition.fromWarehouse
				+"\n接收库"+this.condition.aimWarehouse
				);*/
				
				//var timeS = this.condition.applicationStartDate;
				//var timeE = this.condition.applicationStopDate;
				
				//var FtimeS = timeS==''?"":this.moment(timeS).format("YYYY-MM-DD");
				//var FtimeE = timeE==''?"":this.moment(timeE).format("YYYY-MM-DD");
				debugger;
				//this.$data.condition.applicationStartDate = timeS==''?"":this.moment(timeS).format("YYYY-MM-DD");
				//this.$data.condition.applicationStopDate = timeE==''?"":this.moment(timeE).format("YYYY-MM-DD");
				this.$data.conditions = {};
				//this.$data.condition = {};
				
				this.$http.post(this.API_ROOT+'/scm/allocationOrder/page'
					,this.$data.condition
					,{
						params:{
							start: this.$data.CurentPage, // 开始页
							limit: this.$data.page.pageSize // 结束页
						}
					}
				).then(resp => {
					
					if(resp.data.success){
						resp.data.total = parseInt(resp.data.total);
						// es5写法
						this.$data.tableData = resp.data;
						//debugger;
					}
					else{
						this.$message.error(resp.data.msg);
					}
				},resp => {});
				debugger;
				/*alert("调拨状态："+this.select_value.i1
				+"\n开始日期:"+FtimeS
				+"\n结束日期:"+FtimeE
				);*/
			},
			//选择框
			handleSelectionChanges: function(val) {
				debugger;
				this.$data.multipleSelections = val;
			},
			//列表,当前页切换
			handleCurrentChange: function(currentPage) {
				this.$data.CurentPage = currentPage;
				//this.$data.dictGroup = '';
				this.baseQuery();
			},
			//列表，分页大小切换
			handleSizeChange: function() {
				
			},
			//发出仓库代码与名称转换
			fromWarehouseCov: function(row, column) {
				return this.$data.levelConvertData[row.fromWarehouse];
			},
			//接受仓库代码与名称转换
			aimWarehouseCov: function(row, column) {
				return this.$data.levelConvertData[row.aimWarehouse];
			},
			//仓库转换转换
			warehouseCovert: function() {
				this.$http.get(this.API_ROOT + '/scm/warehouse/convert', {
					params: {}
				}).then((response) => {
					this.$data.levelConvertData = response.data;
				}, (response) => {});
			},
			// 详情按钮
			info: function(index) {
				this.$data.orderList = this.$data.tableData.dataList[index];
				
				
				this.$http.get(this.API_ROOT + '/scm/allocationOrder/carList', {
					params: {
						id: this.$data.tableData.dataList[index].id
					}
				}).then(resp => {
					debugger;
					this.$data.dialogInfoShow = true;
					this.$data.comFormData.allocationOrderDetailList = resp.data.data;
				}, resp => {});
				
				
				debugger;
			},
			//调拨类型
			saleStatusCov: function(row, column) {
				var temp="";
				switch(row.allocationType) {
					case '0':
						temp = "二网调拨";
						break;
					case '1':
						temp = '临时调拨';
						break;
					case "2":
						temp = '外展调拨';
						break;
					default:
						''
						break
				};
				return temp;
			}
			
		},
		//表单创建时执行
		created: function() {
			this.warehouseCovert();
			this.scmQuery();
			//获取仓库的下拉
			this.$http.get(this.API_ROOT + '/scm/warehouse/combo', {
				params: {
				}
			}).then((response) => {
				this.$data.warehouseCombo = response.data;
			}, (response) => {});
			
		},
	}
</script>

<style>
	.queryLabel{
		
	}
</style>